<%@ page import="edu.njfu.sas.dao.StudentDao" %>
<%@ page import="edu.njfu.sas.dao.impl.StudentDaoImpl" %>
<%@ page import="edu.njfu.sas.model.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="edu.njfu.sas.util.PageUtil" %><%--
  Created by IntelliJ IDEA.
  User: guzhe
  Date: 2020/12/10
  Time: 8:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>学生列表展示</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<hr>
<h1 align="center">软件工程18级学生信息表</h1>
<hr>
<form  action="liststudents.jsp" method="post">
    请输入姓名：<input  type="text" name="userName" id="userName"/>
    <input type="submit" name="submit" id="submit" value="确定"/>
</form>
<hr>
<table>
    <tr>
        <td>学号</td>
        <td>姓名</td>
        <td>班级</td>
        <td>性别</td>
        <td>系部</td>
        <td>电话</td>
        <td>宿舍号</td>
        <td>照片</td>
        <td>操作</td>
    </tr>
<%
    String submit = request.getParameter("submit");
    /*
    * 如何修改代码 能够支持分页？
    * */
    String page1=request.getParameter("page");
    int pageSize=5;
    long totalRecords=0;
    int currentPage=0;
    //判断page是否存在？page==null，设置帕合=1，初始值为1
    if(page1==null){
    page1="1";
    }
    currentPage=Integer.parseInt(page1);
    StudentDao sdao=new StudentDaoImpl();
    //优化总记录数,保存到request中
    //totalRecords=sdao.totalRecords();
 Object totals=request.getAttribute("total");
 if(totals==null){
     totalRecords=sdao.totalRecords();
     request.setAttribute("total",totalRecords);
 }else{
     totalRecords=(Long)totals;
 }
 PageUtil pageUtil=new PageUtil(totalRecords,pageSize,currentPage);

    List<Student> students=sdao.getStudentByPaging(pageUtil.getcurrentPage(),pageSize);

    for(Student s:students){
%>
<%--用于学生列表展示--%>
    <tr>
        <td><%=s.getStuNo()%></td>
        <td><%=s.getStuName()%></td>
        <td><%=s.getClasses()%></td>
        <td><%=s.getGender()%></td>
        <td><%=s.getDepartment()%></td>
        <td><%=s.getTel()%></td>
        <td><%=s.getDormNo()%></td>
        <td>
           <img src="<%=s.getPhotoPath()%>" style="width: 50px" height="50px"/>
        </td>
        <td>
            <a href="updatestudent.jsp?stuno=<%=s.getStuNo()%>">更新</a>
        </td>
    </tr>
    <%
        }
     %>
</table>
<hr>
<%@include file="page.jsp"%>
</body>
</html>
